<template>
  <div class="system-info">
    <el-collapse v-model="activeNames" class="bordered-items">
      <el-collapse-item name="version">
        <template #title>
          <div class="collapse-header">
            <div class="header-left">
              <el-icon><InfoFilled /></el-icon>
              <span>系统信息</span>
              <el-tag size="small" type="success" class="version-tag">v1.0.0</el-tag>
            </div>
            <div class="header-right" v-if="!activeNames.includes('version') && !isMobileView">
              <span class="summary-text">Vue 3.5.13 / Node.js 20.x</span>
            </div>
          </div>
        </template>
        <div class="info-content">
          <div class="info-item">
            <span class="label">系统版本</span>
            <span class="value">1.0.0</span>
          </div>
          <div class="info-item">
            <span class="label">更新时间</span>
            <span class="value">2025-02-06</span>
          </div>
          <div class="info-item">
            <span class="label">运行环境</span>
            <span class="value">Node.js 20.x</span>
          </div>
          <div class="info-item">
            <span class="label">框架版本</span>
            <span class="value">Vue 3.5.13 / Vite 6.0.5</span>
          </div>
        </div>
      </el-collapse-item>

      <el-collapse-item name="changelog">
        <template #title>
          <div class="collapse-header">
            <div class="header-left">
              <el-icon><Document /></el-icon>
              <span>更新日志</span>
              <el-tag size="small" type="warning" class="update-tag">最近更新</el-tag>
            </div>
            <div class="header-right" v-if="!activeNames.includes('changelog') && !isMobileView">
              <span class="summary-text">3 个新功能 / 2 项优化</span>
            </div>
          </div>
        </template>
        <div class="changelog-content">
          <div class="version-item">
            <div class="version-header">
              <span class="version">v1.0.0</span>
              <span class="date">2025-02-06</span>
            </div>
            <div class="changes">
              <div class="change-item">
                <el-tag size="small" type="success">新增</el-tag>
                <span>仪表盘数据可视化功能</span>
              </div>
              <div class="change-item">
                <el-tag size="small" type="success">新增</el-tag>
                <span>文章发布热力图展示</span>
              </div>
              <div class="change-item">
                <el-tag size="small" type="warning">优化</el-tag>
                <span>访客地域分布交互体验</span>
              </div>
            </div>
          </div>

          <div class="version-item">
            <div class="version-header">
              <span class="version">v0.9.0</span>
              <span class="date">2025-01-15</span>
            </div>
            <div class="changes">
              <div class="change-item">
                <el-tag size="small" type="success">新增</el-tag>
                <span>Markdown 编辑器集成</span>
              </div>
              <div class="change-item">
                <el-tag size="small" type="danger">修复</el-tag>
                <span>文章保存偶发性失败问题</span>
              </div>
            </div>
          </div>

          <div class="version-item">
            <div class="version-header">
              <span class="version">v0.8.0</span>
              <span class="date">2024-12-20</span>
            </div>
            <div class="changes">
              <div class="change-item">
                <el-tag size="small" type="success">新增</el-tag>
                <span>评论管理功能</span>
              </div>
              <div class="change-item">
                <el-tag size="small" type="warning">优化</el-tag>
                <span>后台整体性能提升</span>
              </div>
            </div>
          </div>
        </div>
      </el-collapse-item>
    </el-collapse>
  </div>
</template>

<script setup>
import { ref, computed, onMounted, onUnmounted } from 'vue'
import { InfoFilled, Document } from '@element-plus/icons-vue'

const activeNames = ref([])

// 移动端视图判断
const isMobileView = computed(() => {
  return window.innerWidth <= 768
})

// 监听窗口大小变化
const handleResize = () => {
  // 窗口大小变化时会自动触发 computed 重新计算
}

// 组件挂载时添加监听器
onMounted(() => {
  window.addEventListener('resize', handleResize)
})

// 组件卸载时移除监听器
onUnmounted(() => {
  window.removeEventListener('resize', handleResize)
})
</script>

<style lang="scss" scoped>
.system-info {
  .bordered-items {
    border: 1px solid var(--el-border-color-lighter);
    border-radius: 8px;
    background-color: var(--el-bg-color);

    @media (max-width: 768px) {
      border-radius: 6px;
    }

    :deep(.el-collapse-item) {
      &:last-child {
        .el-collapse-item__header {
          border-bottom: none;
        }
      }

      .el-collapse-item__header {
        padding: 12px 16px;
        font-size: 14px;
        border-radius: 6px;
        border-bottom: 1px solid var(--el-border-color-lighter);
        background-color: var(--el-bg-color);
        height: 46px;

        @media (max-width: 768px) {
          padding: 10px 12px;
          font-size: 13px;
          height: 42px;
        }

        &:hover {
          background-color: var(--el-fill-color-light);
        }

        &.is-active {
          border-bottom-color: var(--el-border-color-lighter);
        }
      }

      .el-collapse-item__content {
        padding: 16px;

        @media (max-width: 768px) {
          padding: 12px;
        }
      }
    }
  }

  .collapse-header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 6px;

    @media (max-width: 768px) {
      flex-wrap: wrap;
    }

    .header-left {
      display: flex;
      align-items: center;
      gap: 8px;
      min-width: 0;

      @media (max-width: 768px) {
        gap: 6px;
        flex: 1;
      }

      .el-icon {
        font-size: 16px;
        color: var(--el-text-color-secondary);
        flex-shrink: 0;

        @media (max-width: 768px) {
          font-size: 14px;
        }
      }

      span {
        @media (max-width: 768px) {
          font-size: 13px;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
        }
      }

      .version-tag,
      .update-tag {
        font-weight: 500;
        flex-shrink: 0;

        @media (max-width: 768px) {
          transform: scale(0.9);
          transform-origin: left center;
        }
      }
    }

    .header-right {
      @media (max-width: 768px) {
        display: none;
      }

      .summary-text {
        font-size: 13px;
        color: var(--el-text-color-secondary);
      }
    }
  }

  .info-content {
    .info-item {
      display: flex;
      align-items: center;
      margin-bottom: 12px;

      @media (max-width: 768px) {
        margin-bottom: 8px;
      }

      &:last-child {
        margin-bottom: 0;
      }

      .label {
        width: 80px;
        color: var(--el-text-color-secondary);
        font-size: 13px;

        @media (max-width: 768px) {
          width: 70px;
          font-size: 12px;
        }
      }

      .value {
        color: var(--el-text-color-primary);
        font-size: 13px;

        @media (max-width: 768px) {
          font-size: 12px;
        }
      }
    }
  }

  .changelog-content {
    .version-item {
      margin-bottom: 20px;

      @media (max-width: 768px) {
        margin-bottom: 16px;
      }

      &:last-child {
        margin-bottom: 0;
      }

      .version-header {
        display: flex;
        align-items: center;
        margin-bottom: 12px;

        @media (max-width: 768px) {
          margin-bottom: 8px;
        }

        .version {
          font-size: 14px;
          font-weight: 600;
          color: var(--el-text-color-primary);

          @media (max-width: 768px) {
            font-size: 13px;
          }
        }

        .date {
          font-size: 13px;
          color: var(--el-text-color-secondary);
          margin-left: 12px;

          @media (max-width: 768px) {
            font-size: 12px;
            margin-left: 8px;
          }
        }
      }

      .changes {
        .change-item {
          display: flex;
          align-items: center;
          gap: 8px;
          margin-bottom: 8px;

          @media (max-width: 768px) {
            gap: 6px;
            margin-bottom: 6px;
          }

          &:last-child {
            margin-bottom: 0;
          }

          .el-tag {
            width: 42px;
            justify-content: center;

            @media (max-width: 768px) {
              width: 36px;
              transform: scale(0.9);
              transform-origin: left center;
            }
          }

          span {
            font-size: 13px;
            color: var(--el-text-color-regular);

            @media (max-width: 768px) {
              font-size: 12px;
            }
          }
        }
      }
    }
  }
}
</style>
